﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IBLL;
using MODEL;
using IDAL;
using DAL;
namespace BLL
{
    public class ProductAttrKeyBLL : BaseBLL<ProductAttrKey, ProductAttrKeyDAL>, IProductAttrKeyBLL
    {


        public List<ProductAttrKey> GetByCategoryID(int categoryId, int isSku)
        {
            return dal.GetByCategoryID(categoryId, isSku);
        }
        public int Update(ProductAttrKey attrKey,List<ProductAttrValue> attrValues)
        {
            //侯海啸
            
             dal.Update(attrKey);
            IProductAttrValueDAL attrValueDAL = new ProductAttrValueDAL();
            var attrValueList = attrValueDAL.GetAllByAttrKeyID(attrKey.ID);
            foreach (var item in attrValueList) {
                attrValueDAL.Delete(item);
            }
            
            foreach (var item in attrValues)
            {
                attrValueDAL.Add(item);
            }
            int result = SaveChange();
            return result;
        }
        public override int Delete(int attrKeyID)
        {
            //侯海啸

            dal.Delete(attrKeyID);
            IProductAttrValueDAL attrValueDAL = new ProductAttrValueDAL();
            var attrValueList = attrValueDAL.GetAllByAttrKeyID(attrKeyID);
            foreach (var item in attrValueList)
            {
                attrValueDAL.Delete(item);
            }
            int result = SaveChange();
            return result;
        }
    }
}
